package com.personal.web.frontend;

import com.personal.entity.HeadLine;
import com.personal.entity.ShopCategory;
import com.personal.service.HeadLineService;
import com.personal.service.ShopCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 萌新
 * @version 1.0
 * @date 2021/4/28 20:43
 */

@Controller
@RequestMapping("/frontend")
public class MainPageController {

    @Autowired
    private HeadLineService headLineService;

    @Autowired
    private ShopCategoryService shopCategoryService;

    @RequestMapping("/listmainpage")
    @ResponseBody
    public Map<String, Object> listMainPage(){
        Map<String, Object> modelMap = new HashMap<>();
        List<ShopCategory> shopCategoryList = new ArrayList<>();
        List<HeadLine> headLineList = new ArrayList<>();

        try {
            //查询状态为1的可见的headLine的信息
            HeadLine headLineCondition = new HeadLine();
            headLineCondition.setEnableStatus(1);
            headLineList= headLineService.queryHeadLineList(headLineCondition);

            modelMap.put("headLineList",headLineList);
        }catch (Exception e) {
            e.getStackTrace();
            modelMap.put("errMsg",e.getMessage());
        }

        try {
            //查询parentId为null的一级类别
            shopCategoryList = shopCategoryService.getShopCategoryList(null);
            modelMap.put("shopCategoryList",shopCategoryList);
        }catch (Exception e){
            e.getStackTrace();
            modelMap.put("success",false);
            modelMap.put("errMsg",e.getMessage());
        }

        modelMap.put("success",true);

        return modelMap;
    }

}
